//


import UIKit

class BaseViewController: UIViewController {
    
    //声明一个属性myBlock，type为闭包可选类型
    //闭包类型：()->() ，无参数，无返回值 点击触发使用
    var myBlock:(()->())?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        self.navigationController?.navigationBar.backgroundColor = UIColor.white
        self.navigationController?.navigationBar.shadowImage = UIImage()
        setupLeftSetting()//调用
    }
    //标题
    func setNavTitle(_ text:String) {
        self.navigationItem.title = text
        self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 20),NSAttributedString.Key.foregroundColor:UIColor.red]
    }
    //返回键
    func setupLeftSetting() {
        if isShowLeftSetting() {//判断
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
            button.setBackgroundImage(UIImage(named: "arrow2"), for: .normal)
            button.addTarget(self, action: #selector(ddddd(click:)), for: .touchUpInside)
            let leftV:UIBarButtonItem = UIBarButtonItem.init(customView: button)
            self.navigationItem.leftBarButtonItem = leftV
        }
    }
    
    //back事件
    @objc func ddddd(click:UIButton) {
        self.navigationController?.popViewController(animated: true)
    }
    //MARK: 是否显示左键
    func isShowLeftSetting() -> Bool {
        return true
    }
    //youjian
    func setupRightSetting(_ obj:Any , myBlocks:@escaping (()->()))  {
        myBlock = myBlocks//点击触发
        if obj is String{
            
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
            button.setTitle(obj as? String, for: .normal)
            button.setTitleColor(UIColor.black, for: .normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            button.addTarget(self, action: #selector(blockClick), for: .touchUpInside)
            let leftV:UIBarButtonItem = UIBarButtonItem.init(customView: button)
            self.navigationItem.rightBarButtonItem = leftV
            //            myBlocks()//运行触发
            
        }else if  obj is UIImage {
            
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
            button.setBackgroundImage(UIImage(named: "arrow2"), for: .normal)
            button.addTarget(self, action: #selector(blockClick), for: .touchUpInside)
            let leftV:UIBarButtonItem = UIBarButtonItem.init(customView: button)
            self.navigationItem.rightBarButtonItem = leftV
            //            myBlocks()//运行触发
        }
        
    }
    // 右键点击事件
    @objc func blockClick() {
        if self.myBlock != nil {
            self.myBlock!()
        }
    }
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}
